package me.sdevil507.supports.upload.repository;

import me.sdevil507.supports.upload.po.AttachFile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface AttachFileRepository extends JpaRepository<AttachFile, Long>, JpaSpecificationExecutor<AttachFile>, QuerydslPredicateExecutor<AttachFile> {
    /**
     * 逻辑删除
     *
     * @param id 附件id
     */
    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update AttachFile a set a.isDel=true where a.id=:id")
    void logicDelete(@Param("id") Long id);


    List<AttachFile> getAllByRelationId(Long relationId);


    AttachFile getAttachFileByRelationId(Long relationId);

    AttachFile getAttachFileById(Long id);
}
